package com.gugee.tiktok.common.model.dal.music;


import com.gugee.tiktok.common.model.mysql.MusicRecord;
import com.gugee.tiktok.common.model.ranking.GrowthData;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Optional;

public interface MusicRecordRepository extends CrudRepository<MusicRecord,Long> {

    Optional<MusicRecord> findByMidAndDateCode(long mid, int dateCode);

    List<MusicRecord> findByMidAndDateCodeBetweenOrderByDateCode(long mid, long dateCodeStart, int dateCodeEnd);

    @Query("SELECT " +
            "IFNULL(ROUND(AVG(user_growth)),0) user_growth " +
            "FROM music_record where mid = :mid and user_growth >0 and date_code BETWEEN :startDateCode AND :endDateCode")
    GrowthData findByGrowthData(long mid, int startDateCode, int endDateCode);
}
